package com.utry.netty;

import com.utry.netty.client.NettyClient;
import com.utry.netty.intf.MessageClientCallback;
import com.utry.netty.intf.MessageServerCallback;
import com.utry.netty.server.NettyServer;

public class NettyUtil {

    private volatile static NettyUtil instance = null;
    private NettyClient client;

    public static NettyUtil getInstance() {
        if (instance == null) {
            synchronized (NettyUtil.class) {
                if (instance == null) {
                    instance = new NettyUtil();
                }
            }
        }
        return instance;
    }

    public void nettyConnect(final MessageClientCallback messageClientCallback) {
            client = NettyClient.getInstance();
            client.setMessageClientCallback(new MessageClientCallback() {
                @Override
                public void messageClientCallback(final String message) {
                    if (messageClientCallback != null) {
                        messageClientCallback.messageClientCallback(message);
                    }
                }
            });
    }

    private void nettyClient(final MessageClientCallback messageClientCallback) {
        client = NettyClient.getInstance();
        client.setMessageClientCallback(new MessageClientCallback() {
            @Override
            public void messageClientCallback(final String message) {
                if (messageClientCallback != null) {
                    messageClientCallback.messageClientCallback(message);
                }
            }
        });
    }
}
